﻿using Kingdee.BOS;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;

namespace CB.KM.ZH.SettleBillUpdateSettlePrice
{
    public class UtilityManager
    {
        /// <summary>
        /// 通过ID获取给字段赋值的DynamicObject
        /// </summary>
        /// <param name="context">K3的Context</param>
        /// <param name="FormId">表单唯一标识</param>
        /// <param name="fieldId">字段唯一标识</param>
        /// <param name="Vaule">字段值</param>
        /// <returns></returns>
        public static DynamicObject GetDynamicObjectById(Context context, string FormId, string fieldId, object Vaule)
        {
            DynamicObject obj;
            try
            {
                if (Vaule == null || Vaule.ToStringV1() == "" || Convert.ToInt32(Vaule) == 0)
                    return null;
                FormMetadata meta = MetaDataServiceHelper.Load(context, FormId) as FormMetadata;
                BusinessInfo info = meta.BusinessInfo;
                BaseDataField FSaleOrgId = info.GetField(fieldId) as BaseDataField;
                obj = BusinessDataServiceHelper.LoadSingle(context, Vaule, FSaleOrgId.RefFormDynamicObjectType);

            }
            catch (Exception ex)
            {
                obj = null;
            }
            return obj;
        }


    }


}
